home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / FROMUTS / CDUNGEON / !CDUNGEON / c / DINIT < prev    next >
Text File  |  1992-03-25  |  13KB  |  474 lines

  1. /* INIT-- DUNGEON INITIALIZATION SUBROUTINE */
  2.  
  3. /*COPYRIGHT 1980, INFOCOM COMPUTERS AND COMMUNICATIONS, CAMBRIDGE MA. 02142*/
  4. /* ALL RIGHTS RESERVED, COMMERCIAL USAGE STRICTLY PROHIBITED */
  5. /* WRITTEN BY R. M. SUPNIK */
  6.  
  7. #include <stdio.h>
  8.  
  9. #ifdef __AMOS__
  10. #include <amos.h>
  11. #endif
  12.  
  13. #include "funcs.h"
  14. #include "vars.h"
  15.  
  16. /* This is here to avoid depending on the existence of <stdlib.h> */
  17.  
  18. extern void srand P((unsigned int));
  19.  
  20. FILE *dbfile;
  21.  
  22. #ifndef TEXTFILE
  23. #ifdef __AMOS__
  24. #define TEXTFILE "lib:dtextc.dat"
  25. #else /* ! __AMOS__ */
  26. #ifdef unix
  27. #define TEXTFILE "/usr/games/lib/dunlib/dtextc.dat"
  28. #else /* ! unix */
  29. #ifdef AMIGA
  30. #define TEXTFILE "dungeon:dtextc.dat"
  31. #else /* ! AMIGA */
  32. #ifdef ARM
  33. #define TEXTFILE "<CDUNGEON$Dir>.dtextc.dtextc_dat"
  34. #else /* ! ARM */
  35.  I need a definition for TEXTFILE
  36. #endif /* ! ARM */
  37. #endif /* ! AMIGA */
  38. #endif /* ! unix */
  39. #endif /* ! __AMOS__ */
  40. #endif /* ! TEXTFILE */
  41.  
  42. #ifndef LOCALTEXTFILE
  43. #define LOCALTEXTFILE "dtextc.dat"
  44. #endif
  45.  
  46. /* Read a single two byte integer from the index file */
  47.  
  48. #define rdint(indxfile) \
  49.     (ch = getc(indxfile), \
  50.      ((ch > 127) ? (ch - 256) : (ch)) * 256 + getc(indxfile))
  51.  
  52. /* Read a number of two byte integers from the index file */
  53.  
  54. static void rdints(c, pi, indxfile)
  55. integer c;
  56. integer *pi;
  57. FILE *indxfile;
  58. {
  59.     integer ch;    /* Local variable for rdint */
  60.  
  61.     while (c-- != 0)
  62.     *pi++ = rdint(indxfile);
  63. }
  64.  
  65. /* Read a partial array of integers.  These are stored as index,value
  66.  * pairs.
  67.  */
  68.  
  69. static void rdpartialints(c, pi, indxfile)
  70. integer c;
  71. integer *pi;
  72. FILE *indxfile;
  73. {
  74.     integer ch;    /* Local variable for rdint */
  75.  
  76.     while (1) {
  77.     int i;
  78.  
  79.     if (c < 255) {
  80.         i = getc(indxfile);
  81.         if (i == 255)
  82.         return;
  83.     }
  84.     else {
  85.         i = rdint(indxfile);
  86.         if (i == -1)
  87.         return;
  88.     }
  89.  
  90.     pi[i] = rdint(indxfile);
  91.     }
  92. }
  93.  
  94. /* Read a number of one byte flags from the index file */
  95.  
  96. static void rdflags(c, pf, indxfile)
  97. integer c;
  98. logical *pf;
  99. FILE *indxfile;
  100. {
  101.     while (c-- != 0)
  102.     *pf++ = getc(indxfile);
  103. }
  104.  
  105. logical init_()
  106. {
  107.     /* System generated locals */
  108.     integer i__1;
  109.     logical ret_val;
  110.  
  111.     /* Local variables */
  112.     integer xmax, r2max, dirmax, recno;
  113.     integer i, j, k;
  114.     register integer ch;
  115.     register FILE *indxfile;
  116.     integer mmax, omax, rmax, vmax, amax, cmax, fmax, smax;
  117.  
  118.     more_init();
  119.  
  120. /* FIRST CHECK FOR PROTECTION VIOLATION */
  121.  
  122.     if (protected()) {
  123.     goto L10000;
  124.     }
  125. /*                         !PROTECTION VIOLATION? */
  126.     more_output("There appears before you a threatening figure clad all over");
  127.     more_output("in heavy black armor.  His legs seem like the massive trunk");
  128.     more_output("of the oak tree.  His broad shoulders and helmeted head loom");
  129.     more_output("high over your own puny frame, and you realize that his powerful");
  130.     more_output("arms could easily crush the very life from your body.  There");
  131.     more_output("hangs from his belt a veritable arsenal of deadly weapons:");
  132.     more_output("sword, mace, ball and chain, dagger, lance, and trident.");
  133.     more_output("He speaks with a commanding voice:");
  134.     more_output("");
  135.     more_output("                    \"You shall not pass.\"");
  136.     more_output("");
  137.     more_output("As he grabs you by the neck all grows dim about you.");
  138.     exit_();
  139.  
  140. /* NOW START INITIALIZATION PROPER */
  141.  
  142. L10000:
  143.     ret_val = FALSE_;
  144. /*                         !ASSUME INIT FAILS. */
  145.     mmax = 1050;
  146. /*                         !SET UP ARRAY LIMITS. */
  147.     omax = 220;
  148.     rmax = 200;
  149.     vmax = 4;
  150.     amax = 4;
  151.     cmax = 25;
  152.     fmax = 46;
  153.     smax = 22;
  154.     xmax = 900;
  155.     r2max = 20;
  156.     dirmax = 15;
  157.  
  158.     rmsg_1.mlnt = 0;
  159. /*                         !INIT ARRAY COUNTERS. */
  160.     objcts_1.olnt = 0;
  161.     rooms_1.rlnt = 0;
  162.     vill_1.vlnt = 0;
  163.     advs_1.alnt = 0;
  164.     cevent_1.clnt = 0;
  165.     exits_1.xlnt = 1;
  166.     oroom2_1.r2lnt = 0;
  167.  
  168.     state_1.ltshft = 10;
  169. /*                         !SET UP STATE VARIABLES. */
  170.     state_1.mxscor = state_1.ltshft;
  171.     state_1.egscor = 0;
  172.     state_1.egmxsc = 0;
  173.     state_1.mxload = 100;
  174.     state_1.rwscor = 0;
  175.     state_1.deaths = 0;
  176.     state_1.moves = 0;
  177.     time_1.pltime = 0;
  178.     state_1.mungrm = 0;
  179.     state_1.hs = 0;
  180.     prsvec_1.prsa = 0;
  181. /*                         !CLEAR PARSE VECTOR. */
  182.     prsvec_1.prsi = 0;
  183.     prsvec_1.prso = 0;
  184.     prsvec_1.prscon = 1;
  185.     orphs_1.oflag = 0;
  186. /*                         !CLEAR ORPHANS. */
  187.     orphs_1.oact = 0;
  188.     orphs_1.oslot = 0;
  189.     orphs_1.oprep = 0;
  190.     orphs_1.oname = 0;
  191.     hack_1.thfflg = FALSE_;
  192. /*                         !THIEF NOT INTRODUCED BUT */
  193.     hack_1.thfact = TRUE_;
  194. /*                         !IS ACTIVE. */
  195.     hack_1.swdact = FALSE_;
  196. /*                         !SWORD IS INACTIVE. */
  197.     hack_1.swdsta = 0;
  198. /*                         !SWORD IS OFF. */
  199.  
  200.     recno = 1;
  201. /*                         !INIT DB FILE POINTER. */
  202.     star_1.mbase = 0;
  203. /*                         !INIT MELEE BASE. */
  204. /* INIT, PAGE 3 */
  205.  
  206. /* INIT ALL ARRAYS. */
  207.  
  208.     i__1 = cmax;
  209.     for (i = 1; i <= i__1; ++i) {
  210. /*                         !CLEAR CLOCK EVENTS */
  211.     cevent_1.cflag[i - 1] = FALSE_;
  212.     cevent_1.ctick[i - 1] = 0;
  213.     cevent_1.cactio[i - 1] = 0;
  214. /* L5: */
  215.     }
  216.  
  217.     i__1 = fmax;
  218.     for (i = 1; i <= i__1; ++i) {
  219. /*                         !CLEAR FLAGS. */
  220.     flags[i - 1] = FALSE_;
  221. /* L10: */
  222.     }
  223.     findex_1.buoyf = TRUE_;
  224. /*                         !SOME START AS TRUE. */
  225.     findex_1.egyptf = TRUE_;
  226.     findex_1.cagetf = TRUE_;
  227.     findex_1.mr1f = TRUE_;
  228.     findex_1.mr2f = TRUE_;
  229.     findex_1.follwf = TRUE_;
  230.     i__1 = smax;
  231.     for (i = 1; i <= i__1; ++i) {
  232. /*                         !CLEAR SWITCHES. */
  233.     switch_[i - 1] = 0;
  234. /* L12: */
  235.     }
  236.     findex_1.ormtch = 4;
  237. /*                         !NUMBER OF MATCHES. */
  238.     findex_1.lcell = 1;
  239.     findex_1.pnumb = 1;
  240.     findex_1.mdir = 270;
  241.     findex_1.mloc = rindex_1.mrb;
  242.     findex_1.cphere = 10;
  243.  
  244.     i__1 = r2max;
  245.     for (i = 1; i <= i__1; ++i) {
  246. /*                         !CLEAR ROOM 2 ARRAY. */
  247.     oroom2_1.rroom2[i - 1] = 0;
  248.     oroom2_1.oroom2[i - 1] = 0;
  249. /* L15: */
  250.     }
  251.  
  252.     i__1 = xmax;
  253.     for (i = 1; i <= i__1; ++i) {
  254. /*                         !CLEAR TRAVEL ARRAY. */
  255.     exits_1.travel[i - 1] = 0;
  256. /* L20: */
  257.     }
  258.  
  259.     i__1 = vmax;
  260.     for (i = 1; i <= i__1; ++i) {
  261. /*                         !CLEAR VILLAINS ARRAYS. */
  262.     vill_1.vopps[i - 1] = 0;
  263.     vill_1.vprob[i - 1] = 0;
  264.     vill_1.villns[i - 1] = 0;
  265.     vill_1.vbest[i - 1] = 0;
  266.     vill_1.vmelee[i - 1] = 0;
  267. /* L30: */
  268.     }
  269.  
  270.     i__1 = omax;
  271.     for (i = 1; i <= i__1; ++i) {
  272. /*                         !CLEAR OBJECT ARRAYS. */
  273.     objcts_1.odesc1[i - 1] = 0;
  274.     objcts_1.odesc2[i - 1] = 0;
  275.     objcts_1.odesco[i - 1] = 0;
  276.     objcts_1.oread[i - 1] = 0;
  277.     objcts_1.oactio[i - 1] = 0;
  278.     objcts_1.oflag1[i - 1] = 0;
  279.     objcts_1.oflag2[i - 1] = 0;
  280.     objcts_1.ofval[i - 1] = 0;
  281.     objcts_1.otval[i - 1] = 0;
  282.     objcts_1.osize[i - 1] = 0;
  283.     objcts_1.ocapac[i - 1] = 0;
  284.     objcts_1.ocan[i - 1] = 0;
  285.     objcts_1.oadv[i - 1] = 0;
  286.     objcts_1.oroom[i - 1] = 0;
  287. /* L40: */
  288.     }
  289.  
  290.     i__1 = rmax;
  291.     for (i = 1; i <= i__1; ++i) {
  292. /*                         !CLEAR ROOM ARRAYS. */
  293.     rooms_1.rdesc1[i - 1] = 0;
  294.     rooms_1.rdesc2[i - 1] = 0;
  295.     rooms_1.ractio[i - 1] = 0;
  296.     rooms_1.rflag[i - 1] = 0;
  297.     rooms_1.rval[i - 1] = 0;
  298.     rooms_1.rexit[i - 1] = 0;
  299. /* L50: */
  300.     }
  301.  
  302.     i__1 = mmax;
  303.     for (i = 1; i <= i__1; ++i) {
  304. /*                         !CLEAR MESSAGE DIRECTORY. */
  305.     rmsg_1.rtext[i - 1] = 0;
  306. /* L60: */
  307.     }
  308.  
  309.     i__1 = amax;
  310.     for (i = 1; i <= i__1; ++i) {
  311. /*                         !CLEAR ADVENTURER'S ARRAYS. */
  312.     advs_1.aroom[i - 1] = 0;
  313.     advs_1.ascore[i - 1] = 0;
  314.     advs_1.avehic[i - 1] = 0;
  315.     advs_1.aobj[i - 1] = 0;
  316.     advs_1.aactio[i - 1] = 0;
  317.     advs_1.astren[i - 1] = 0;
  318.     advs_1.aflag[i - 1] = 0;
  319. /* L70: */
  320.     }
  321.  
  322.     debug_1.dbgflg = 0;
  323.     debug_1.prsflg = 0;
  324.     debug_1.gdtflg = 0;
  325.  
  326. #ifdef ALLOW_GDT
  327.  
  328. /* allow setting gdtflg true if user id matches wizard id */
  329. /* this way, the wizard doesn't have to recompile to use gdt */
  330.  
  331.     if (wizard()) {
  332.     debug_1.gdtflg = 1;
  333.     }
  334.  
  335. #endif /* ALLOW_GDT */
  336.  
  337.     screen_1.fromdr = 0;
  338. /*                         !INIT SCOL GOODIES. */
  339.     screen_1.scolrm = 0;
  340.     screen_1.scolac = 0;
  341. /* INIT, PAGE 4 */
  342.  
  343. /* NOW RESTORE FROM EXISTING INDEX FILE. */
  344.  
  345. #ifdef __AMOS__
  346.     if ((dbfile = fdopen(ropen(LOCALTEXTFILE, 0), BINREAD)) == NULL &&
  347.     (dbfile = fdopen(ropen(TEXTFILE, 0), BINREAD)) == NULL)
  348. #else
  349.     if ((dbfile = fopen(LOCALTEXTFILE, BINREAD)) == NULL &&
  350.     (dbfile = fopen(TEXTFILE, BINREAD)) == NULL)
  351. #endif
  352.     goto L1950;
  353.  
  354.     indxfile = dbfile;
  355.  
  356.     i = rdint(indxfile);
  357.     j = rdint(indxfile);
  358.     k = rdint(indxfile);
  359.  
  360. /*                         !GET VERSION. */
  361.     if (i != vers_1.vmaj || j != vers_1.vmin) {
  362.     goto L1925;
  363.     }
  364.  
  365.     state_1.mxscor = rdint(indxfile);
  366.     star_1.strbit = rdint(indxfile);
  367.     state_1.egmxsc = rdint(indxfile);
  368.  
  369.     rooms_1.rlnt = rdint(indxfile);
  370.     rdints(rooms_1.rlnt, &rooms_1.rdesc1[0], indxfile);
  371.     rdints(rooms_1.rlnt, &rooms_1.rdesc2[0], indxfile);
  372.     rdints(rooms_1.rlnt, &rooms_1.rexit[0], indxfile);
  373.     rdpartialints(rooms_1.rlnt, &rooms_1.ractio[0], indxfile);
  374.     rdpartialints(rooms_1.rlnt, &rooms_1.rval[0], indxfile);
  375.     rdints(rooms_1.rlnt, &rooms_1.rflag[0], indxfile);
  376.  
  377.     exits_1.xlnt = rdint(indxfile);
  378.     rdints(exits_1.xlnt, &exits_1.travel[0], indxfile);
  379.  
  380.     objcts_1.olnt = rdint(indxfile);
  381.     rdints(objcts_1.olnt, &objcts_1.odesc1[0], indxfile);
  382.     rdints(objcts_1.olnt, &objcts_1.odesc2[0], indxfile);
  383.     rdpartialints(objcts_1.olnt, &objcts_1.odesco[0], indxfile);
  384.     rdpartialints(objcts_1.olnt, &objcts_1.oactio[0], indxfile);
  385.     rdints(objcts_1.olnt, &objcts_1.oflag1[0], indxfile);
  386.     rdpartialints(objcts_1.olnt, &objcts_1.oflag2[0], indxfile);
  387.     rdpartialints(objcts_1.olnt, &objcts_1.ofval[0], indxfile);
  388.     rdpartialints(objcts_1.olnt, &objcts_1.otval[0], indxfile);
  389.     rdints(objcts_1.olnt, &objcts_1.osize[0], indxfile);
  390.     rdpartialints(objcts_1.olnt, &objcts_1.ocapac[0], indxfile);
  391.     rdints(objcts_1.olnt, &objcts_1.oroom[0], indxfile);
  392.     rdpartialints(objcts_1.olnt, &objcts_1.oadv[0], indxfile);
  393.     rdpartialints(objcts_1.olnt, &objcts_1.ocan[0], indxfile);
  394.     rdpartialints(objcts_1.olnt, &objcts_1.oread[0], indxfile);
  395.  
  396.     oroom2_1.r2lnt = rdint(indxfile);
  397.     rdints(oroom2_1.r2lnt, &oroom2_1.oroom2[0], indxfile);
  398.     rdints(oroom2_1.r2lnt, &oroom2_1.rroom2[0], indxfile);
  399.  
  400.     cevent_1.clnt = rdint(indxfile);
  401.     rdints(cevent_1.clnt, &cevent_1.ctick[0], indxfile);
  402.     rdints(cevent_1.clnt, &cevent_1.cactio[0], indxfile);
  403.     rdflags(cevent_1.clnt, &cevent_1.cflag[0], indxfile);
  404.  
  405.     vill_1.vlnt = rdint(indxfile);
  406.     rdints(vill_1.vlnt, &vill_1.villns[0], indxfile);
  407.     rdpartialints(vill_1.vlnt, &vill_1.vprob[0], indxfile);
  408.     rdpartialints(vill_1.vlnt, &vill_1.vopps[0], indxfile);
  409.     rdints(vill_1.vlnt, &vill_1.vbest[0], indxfile);
  410.     rdints(vill_1.vlnt, &vill_1.vmelee[0], indxfile);
  411.  
  412.     advs_1.alnt = rdint(indxfile);
  413.     rdints(advs_1.alnt, &advs_1.aroom[0], indxfile);
  414.     rdpartialints(advs_1.alnt, &advs_1.ascore[0], indxfile);
  415.     rdpartialints(advs_1.alnt, &advs_1.avehic[0], indxfile);
  416.     rdints(advs_1.alnt, &advs_1.aobj[0], indxfile);
  417.     rdints(advs_1.alnt, &advs_1.aactio[0], indxfile);
  418.     rdints(advs_1.alnt, &advs_1.astren[0], indxfile);
  419.     rdpartialints(advs_1.alnt, &advs_1.aflag[0], indxfile);
  420.  
  421.     star_1.mbase = rdint(indxfile);
  422.     rmsg_1.mlnt = rdint(indxfile);
  423.     rdints(rmsg_1.mlnt, &rmsg_1.rtext[0], indxfile);
  424.  
  425. /* Save location of start of message text */
  426.     rmsg_1.mrloc = ftell(indxfile);
  427.  
  428. /*                         !INIT DONE. */
  429.  
  430. /* INIT, PAGE 5 */
  431.  
  432. /* THE INTERNAL DATA BASE IS NOW ESTABLISHED. */
  433. /* SET UP TO PLAY THE GAME. */
  434.  
  435.     itime_(&time_1.shour, &time_1.smin, &time_1.ssec);
  436.     srand(time_1.shour ^ (time_1.smin ^ time_1.ssec));
  437.  
  438.     play_1.winner = aindex_1.player;
  439.     last_1.lastit = advs_1.aobj[aindex_1.player - 1];
  440.     play_1.here = advs_1.aroom[play_1.winner - 1];
  441.     hack_1.thfpos = objcts_1.oroom[oindex_1.thief - 1];
  442.     state_1.bloc = objcts_1.oroom[oindex_1.ballo - 1];
  443.     ret_val = TRUE_;
  444.  
  445.     return ret_val;
  446. /* INIT, PAGE 6 */
  447.  
  448. /* ERRORS-- INIT FAILS. */
  449.  
  450. L1925:
  451.     more_output(NULL);
  452.     printf("%s is version %1d.%1d%c.\n", TEXTFILE, i, j, k);
  453.     more_output(NULL);
  454.     printf("I require version %1d.%1d%c.\n", vers_1.vmaj, vers_1.vmin,
  455.        vers_1.vedit);
  456.     goto L1975;
  457. L1950:
  458.     more_output(NULL);
  459.     printf("I can't open %s.\n", TEXTFILE);
  460. L1975:
  461.     more_output("Suddenly a sinister, wraithlike figure appears before you,");
  462.     more_output("seeming to float in the air.  In a low, sorrowful voice he says,");
  463.     more_output("\"Alas, the very nature of the world has changed, and the dungeon");
  464.     more_output("cannot be found.  All must now pass away.\"  Raising his oaken staff");
  465.     more_output("in farewell, he fades into the spreading darkness.  In his place");
  466.     more_output("appears a tastefully lettered sign reading:");
  467.     more_output("");
  468.     more_output("                       INITIALIZATION FAILURE");
  469.     more_output("");
  470.     more_output("The darkness becomes all encompassing, and your vision fails.");
  471.     return ret_val;
  472.  
  473. } /* init_ */
  474.